// 2025/3/29
// 两个链表的第一个公共结点

/*
struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :
			val(x), next(NULL) {
	}
};*/
class Solution {
    public:
        ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2) {
            ListNode *cur1 = pHead1, *cur2 = pHead2;
            int count1 = 0, count2 = 0;
            while(cur1 || cur2)
            {
                if(cur1) cur1 = cur1->next;
                else count2++;
                if(cur2) cur2 = cur2->next;
                else count1++;
            }
            while(count1--) pHead1 = pHead1->next;
            while(count2--) pHead2 = pHead2->next;
            while(pHead1 && pHead2 && pHead1->val != pHead2->val)
            {
                pHead1 = pHead1->next;
                pHead2 = pHead2->next;
            }
            return pHead1;
        }
    };
    